package com.hd.tiyu.yuejian.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.tiyu.yuejian.JavaBean.OrderDetail;
import com.hd.tiyu.yuejian.Model.UserModel;
import com.hd.tiyu.yuejian.R;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class OrderDetailActivity extends AppCompatActivity {
    private ImageView orderdetail_back,orderdetail_photo;
    private TextView name;
    private TextView price;
    private TextView start_time;
    private TextView total;
    private TextView update_time;
    private TextView dingdannum;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_detail);
        initViews();
        initData();
        initEvents();
    }
    private void initViews() {
        orderdetail_back=(ImageView) findViewById(R.id.img_orderdetail_back);
        orderdetail_photo=(ImageView) findViewById(R.id.img_detail_photo);

        name=(TextView) findViewById(R.id.text_Name);
        price=(TextView) findViewById(R.id.text_price);
        start_time=(TextView) findViewById(R.id.tex_starttime);
        total=(TextView) findViewById(R.id.tex_pay);
        update_time=(TextView) findViewById(R.id.tex_paytime);
        dingdannum=(TextView) findViewById(R.id.text_dingdanbianhao);


    }

    private void initData() {
        Intent intent=getIntent();
        String Orderid=intent.getStringExtra("id");
        String type   =intent.getStringExtra("paytype");
        UserModel userModel=new UserModel();
        Call<OrderDetail> call=userModel.getOrderDetail(Orderid,type);
        call.enqueue(new Callback<OrderDetail>() {
            @Override
            public void onResponse(Call<OrderDetail> call, Response<OrderDetail> response) {
                OrderDetail data=response.body();
                name.setText(data.getName());
                price.setText(data.getPrice());
                start_time.setText(data.getStart_date());
                total.setText(data.getPay());
                update_time.setText(data.getAdultnum());
                dingdannum.setText(data.getId());
                Picasso.with(OrderDetailActivity.this)
                        .load("http://172.24.10.175/workout/Uploads/"+data.getThumb())
                        .resize(400,325).centerCrop()
                        .into(orderdetail_photo);
            }

            @Override
            public void onFailure(Call<OrderDetail> call, Throwable t) {

            }
        });



    }



    private void initEvents() {
        orderdetail_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }
}
